package logiexport.session;

import logiexport.pojos.User;
import logiexport.bd.*;

import org.apache.wicket.Session;
import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.request.Request;

public class SignInSession extends AuthenticatedWebSession {

	User user;
	App app = new App();

	public SignInSession(Request request) {
		super(request);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean authenticate(String email, String password) {
		// TODO Auto-generated method stub

		System.out.println("authenticate!!!!");
		
		user=app.login(email,password);
		
		if(user==null) {
			return false;
		}
		else
			return true;
		
	
	}

	public static SignInSession get() {
		return (SignInSession) Session.get();
	}

	@Override
	public Roles getRoles() {
		// TODO Auto-generated method stub
		if (isSignedIn()) {
			return new Roles(Roles.USER);
		}

		return new Roles();
	}

	/**
	 * @return User
	 */
	public User getUser() {
		return user;
	}

	/**
	 * @param user
	 *            New user
	 */
	public void setUser(final User u) {
		this.user = u;
	}

}
